# Create your views here.
from django.http import HttpResponse
from polls.models import Poll
from django.shortcuts import render, get_object_or_404
from django.core.urlresolvers import reverse

def index(request):
    latest_poll_list = Poll.objects.order_by("-pub_date")[:5]
    context = {"latest_poll_list" : latest_poll_list }
    return render(request, "polls/index.html", context)

def vote(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    try:
        selectedchoice = p.choice_set.get(pk=request.POST["choice"])
    except (KeyError, ChoiceDoesNotExist):
        return render(request, "polls/detail.html", {"poll"})

def results(request, poll_id):
    return HttpResponse("You are looking at the results of poll %s" % poll_id)

def detail(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    return render(request, "polls/detail.html", {"poll": poll})

